package com.afdor.rws.event.driven.support;

import com.afdor.rws.annotation.extension.Extension;
import com.afdor.rws.event.driven.EventSource;
import com.afdor.rws.event.driven.channel.ChannelProvider;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;

/**
 * 事件源配置信息
 *
 * @author 悭梵
 * @date Created in 2018-08-14 18:31
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Extension(value = "default", order = Extension.NORMAL_ORDER - 100, scope = Extension.Scope.PROTOTYPE, interfaceClass = EventSource.class)
public class DefaultEventSource<C extends ChannelProvider> implements EventSource<C> {

    @NonNull
    private String eventSourceName;
    @NonNull
    private C channelProvider;

    @Override
    public <T extends EventSource<C>> T setChannelProvider(@NonNull C channelProvider) {
        if (channelProvider == null || StringUtils.isBlank(channelProvider.getEventSourceName())) {
            throw new NullPointerException("事件执行通道配置不全");
        }
        this.channelProvider = channelProvider;
        this.eventSourceName = channelProvider.getEventSourceName();
        return (T) this;
    }

}
